// pages/company/take/take.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isAll: false, //全选
        isItem: false, //单选
        nemItems: [],
        radios: [{
                id: 1,
                value: '1',
                text: '扫运单号',
                checked: true
            },
            // {
            //     id: 2,
            //     value: '2',
            //     text: '扫运单+客户条码',
            //     checked: false
            // },
            // {
            //     id: 3,
            //     value: '3',
            //     text: '人工点数',
            //     checked: false
            // },
        ],
        allnum: 0, //总数量
        itemNums: 0, //扫描数量
        value: 1, //扫描切换
        codes:[],
        total:0,
        scanCodesList:[],//提交数组
        index:0,
        code:'',
        isTip:false,
        isSave:false,
        isLink:false
    },
    // radioChange: function(e) { //radioChange
    //     var that = this;
    //     var items = [];
    //     var value = 1
    //     for (var i = 0; i < that.data.radios.length; i++) {
    //         var item = that.data.radios[i]
    //         item.checked = false
    //         if (e.detail.value && e.detail.value === that.data.radios[i].value) {
    //             item.checked = true
    //             value = e.detail.value
    //         }
    //         items.push(item)
    //     }
    //     that.setData({
    //         radios: items,
    //         value: value
    //     })
    // },
    /**
     * 生命周期函数--监听页面加载
     */
    onShow(){
      var that=this
      that.setData({
        isLink:getApp().globalData.isLink
      })
      
    },
    onLoad: function(options) {
        var that = this
        var target = []
        console.log(options, "数据")
        var item = JSON.parse(options.item)
        var tokenL = app.globalData.token
        console.log(item,"----------")
        if (item.orders) {
          for (var i = 0; i < item.length; i++) {
            for (var j = 0; j < item.orders.orderGoodInfosList.length; j++) {
                item.orders.orderGoodInfosList[j].realQuantity = 0;
                target.push(item.orders.orderGoodInfosList[j]) //添加当前item
                target[target.length - 1]['checked'] = false //对最新一条item插入新字段checked
                target[target.length - 1]['orderId'] = item.orders.id //同上
                target[target.length - 1]['scanCodeType'] = 1 //同上
                target[target.length - 1]['objectId'] = item.id  //同上
            }
          }  
        } else {
            for (var i = 0; i < item.length; i++) {
                for (var k = 0; k < item[i].orders.orderGoodInfosList.length; k++) {
                    item[i].orders.orderGoodInfosList[k].realQuantity = 0;
                    target.push(item[i].orders.orderGoodInfosList[k]) //添加当前item
                    target[target.length - 1]['checked'] = false
                    target[target.length - 1]['orderId'] = item[i].orders.id
                    target[target.length - 1]['scanCodeType'] = 1
                    target[target.length - 1]['objectId'] = item[i].id  //同上
                }
            }
        }
        var allnum = 0
        for (var i = 0; i < target.length; i++) {
            allnum += target[i].nums
        }
        console.log(target,"target")
        that.setData({
            nemItems: target,
            allnum: allnum,
            index: options.index
        })
        if (that.data.index==2){
          wx.setNavigationBarTitle({
            title: '装车'
          })  
        }
        if (that.data.index == 3) {
          wx.setNavigationBarTitle({
            title: '收货'
          })
        }
        if (that.data.index == 4) {
          wx.setNavigationBarTitle({
            title: '发货'
          })
        }
        console.log(that.data.index,"that.data.index")
        wx.showLoading({
          title: "加载中",
          mask:true
        });
        var ordersList = []
        console.log(that.data.nemItems,"that.data.nemItems")
        for (var i = 0; i < that.data.nemItems.length; i++) {
          ordersList[i] = Object.assign({ id: that.data.nemItems[i].orderId, objectId: that.data.nemItems[i].objectId });
        }

        wx.request({
          url: app.globalData.apiServer + "/api/Orders/GetCodesAndClientCodeByBatchOrder",
          data: {
            ordersList,
            scanCodeType: that.data.index
          },
          method: "POST",
          header: {
            'content-type': 'application/json',
            "Authorization": "Bearer " + tokenL,
            "LoginType": 4
          },
          success: function (res) {
            if (res.data.responseCode == 1000) {
              that.setData({
                lists: res.data.obj //
              })
            let lists = res.data.obj;
            let newNemItems = that.data.nemItems.map((item, index) => {
              if (that.data.index == 2) {
                let _item = item;
                let _codeList = lists[index].codeInfoList.map((itm, idx) => {
                  return {
                    code: itm.code,
                    isScaned: itm.isScaned
                  }
                })
                _item.codeList = _codeList;
                _item.numsy = _item.nums - _item.loadNums
                return _item;
              }
              if (that.data.index == 3) {
                let _item = item;
                let _codeList = lists[index].codeInfoList.map((itm, idx) => {
                  // let flag = ['215508810605', '222', '812026813790'].indexOf(itm) > 0 ? true : false;
                  return {
                    code: itm.code,
                    isScaned: itm.isScaned
                  }
                })
                _item.codeList = _codeList;
                _item.numsy = _item.nums - _item.inNums
                return _item;
              }
              if (that.data.index == 4) {
                let _item = item;
                let _codeList = lists[index].codeInfoList.map((itm, idx) => {
                  // let flag = ['215508810605', '222', '812026813790'].indexOf(itm) > 0 ? true : false;
                  return {
                    code: itm.code,
                    isScaned: itm.isScaned
                  }
                })
                _item.codeList = _codeList;
                _item.numsy = _item.nums - _item.outNums
                return _item;
              }
            })
            that.setData({
              nemItems: newNemItems,
            })
            var total=0
            for (var i = 0; i < that.data.nemItems.length; i++) {
              for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
                if (that.data.nemItems[i].codeList[j].isScaned == true) {
                  total ++
                }
              }
            } 
            that.setData({
              total: total,
            })
            wx.hideLoading();
            console.log(newNemItems,"newNemItems")
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              });
            }

          }

        })
    },
    allCheck() { //多选
        var that = this
        that.setData({
            isAll: !that.data.isAll
        })
        if (that.data.isAll == true) {
            var values = [];
            for (var i = 0, len = that.data.nemItems.length; i < len; i++) {
                values.push(that.data.nemItems[i].id.toString());
            }
            this.itemCheck({ currentTarget: { dataset: { id: values } } });
        } else {
            this.itemCheck({ currentTarget: { dataset: { id: [] } } });
        }
    },
    itemCheck(e) { //单选
        var that = this
        var checked = e.currentTarget.dataset.id;
        var items = [];
        for (var i = 0; i < that.data.nemItems.length; i++) {
            if (checked.indexOf(that.data.nemItems[i].id.toString()) !== -1) {
                //实取数量
                if (that.data.nemItems[i].checked == true) {
                    items[i] = Object.assign({}, that.data.nemItems[i], { checked: false });
                } else {
                    items[i] = Object.assign({}, that.data.nemItems[i], { checked: true });
                }
            } else {
                items[i] = Object.assign({}, that.data.nemItems[i]);
            }
        }
        var itemNums = 0
        for (var i = 0; i < items.length; i++) {
            if (items[i].checked == true) {
                itemNums += items[i].nums
            }
        }

        that.setData({
            nemItems: items,
            itemNums: itemNums
        })
    },


    toLogs(e) { //跳转扫描
        var that = this
        var list = []
        for (var i = 0; i < that.data.nemItems.length; i++) {
            if (that.data.nemItems[i].checked == true) {
                list.push(that.data.nemItems[i])
            }
        }
        var item = JSON.stringify(list);
        // if (list.length > 1) {
        //     wx.showToast({
        //         title: '暂支持单一商品',
        //         icon: 'loading',
        //         duration: 2000
        //     });
        //     return false
        // }
        if (list.length > 0) {
            // wx.navigateTo({
            //     url: '../logs/logs?item=' + item+"&index="+e.currentTarget.dataset.index
            // })
            // wx.showToast({
            //   title: '功能正在开发',
            //   icon: 'loading',
            //   duration: 2000
            // });
        }
        var that = this
        // var list = []
        // for (var i = 0; i < that.data.nemItems.length; i++) {
        //     if (that.data.nemItems[i].checked == true) {
        //         list.push(that.data.nemItems[i])
        //     }
        // }
        var item = JSON.stringify(that.data.nemItems);
        // if (list.length > 1) {
        //     wx.showToast({
        //         title: '暂支持单一商品',
        //         icon: 'loading',
        //         duration: 2000
        //     });
        //     return false
        // }
        if (that.data.nemItems.length > 0) {
            wx.navigateTo({
              url: '../bluetooth/bluetooth'
            })
            // wx.showToast({
            //   title: '功能正在开发',
            //   icon: 'loading',
            //   duration: 2000
            // });
        } else {
            wx.showToast({
                title: '请选择商品',
                icon: 'loading',
                duration: 2000
            });
        }

    },
    addorder() { //跳转新增订单
        wx.navigateTo({
            url: '../addorder/addorder',
        })
    },
  tui(){
    // wx.navigateTo({
    //   url: '../logReturn/logReturn',
    // })   
    wx.showToast({
      title: '功能正在开发',
      icon: 'none',
      duration: 2000
    });
  },
  setCode: function (c) {// 
    var newcodes=[]
    var that = this
    that.setData({
      code:c
    })
    newcodes.push(c)
    if (that.data.lists.length && that.data.lists[0].codeList.length){
      let flag = false;
      let isComp = false;
      for (var i = 0; i < that.data.lists.length; i++) {
        for (var j = 0; j < that.data.lists[i].codeList.length;j++){
          if (!isComp) {
            if (c != that.data.lists[i].codeList[j]) {
              flag = false;           
            }else{
              flag = true;
              isComp = true;
            }
          }
        }
      }
      if (flag) {
        that.audioPlay()
             wx.showToast({
                title: '扫码成功',
                icon: 'none',
                duration: 2000
              });  
      } else {
        var buffer = new ArrayBuffer(14)
        var dataView = new DataView(buffer)
        dataView.setUint8(0, 0x40)
        dataView.setUint8(1, 0x0A)
        dataView.setUint8(2, 0x53)
        dataView.setUint8(3, 0x16)
        dataView.setUint8(4, 0x03)
        dataView.setUint8(5, 0x00)
        dataView.setUint8(6, 0x00)
        dataView.setUint8(7, 0x00)
        dataView.setUint8(8, 0x96)
        dataView.setUint8(9, 0x00)
        dataView.setUint8(10, 0x64)
        dataView.setUint8(11, 0x00)
        dataView.setUint8(12, 0x70)
        dataView.setUint8(13, 0x2A)
        // console.log("this_write_cid", that.data.this_write_cid) 
        wx.writeBLECharacteristicValue({
          deviceId: app.globalData.deviceId,
          serviceId: "0000FFF0-0000-1000-8000-00805F9B34FB",
          characteristicId: '0000FFF1-0000-1000-8000-00805F9B34FB',
          value: buffer,
          success: function (res) {

            console.log("writeBLECharacteristicValue", res)
          },
        })
        that.audioPlay1()
            wx.showToast({
              title: '不存在条码',
              icon: 'none',
              duration: 2000
            });
       return false     
      }
    }

    var tokenL = app.globalData.token
    var ordersList = []
    for (var i = 0; i < that.data.nemItems.length; i++) {
      ordersList[i] = Object.assign({ id: that.data.nemItems[i].orderId });
    }

    var isReplay = false
    if (app.globalData.scanCodeList.length){
      
      for (var i = 0; i < app.globalData.scanCodeList.length; i++) { 
        if(c==app.globalData.scanCodeList[i]){
          var buffer = new ArrayBuffer(14)
          var dataView = new DataView(buffer)
          dataView.setUint8(0, 0x40)
          dataView.setUint8(1, 0x0A)
          dataView.setUint8(2, 0x53)
          dataView.setUint8(3, 0x16)
          dataView.setUint8(4, 0x03)
          dataView.setUint8(5, 0x00)
          dataView.setUint8(6, 0x00)
          dataView.setUint8(7, 0x00)
          dataView.setUint8(8, 0x96)
          dataView.setUint8(9, 0x00)
          dataView.setUint8(10, 0x64)
          dataView.setUint8(11, 0x00)
          dataView.setUint8(12, 0x70)
          dataView.setUint8(13, 0x2A)
          // console.log("this_write_cid", that.data.this_write_cid) 
          wx.writeBLECharacteristicValue({
            deviceId: app.globalData.deviceId,
            serviceId: "0000FFF0-0000-1000-8000-00805F9B34FB",
            characteristicId: '0000FFF1-0000-1000-8000-00805F9B34FB',
            value: buffer,
            success: function (res) {

              console.log("writeBLECharacteristicValue", res)
            },
          })
          that.audioPlay2()
          wx.showToast({
            title:'请勿重复扫描',
            icon: 'none',
            duration: 2000
          }); 
          isReplay=true
          console.log('重复：' + app.globalData.scanCodeList[i])   
          return false     
        }
      }  
    }
    if (isReplay){
      return false   
    }else{
      console.log('无重复')
      app.globalData.scanCodeList.push(c)
      console.log(app.globalData.scanCodeList, "app.globalData.scanCodeList")
      if (app.globalData.scanCodeList) {
        that.setData({
          codes: that.unique1(app.globalData.scanCodeList)
        })
      }
      if (that.data.codes.length) {//

        let lists = that.data.lists;
        let total = 0;
        let newNemItems = that.data.nemItems.map((item, index) => {
          if (that.data.index == 2) {
            let num = item.loadNums;
            let _item = item;
            let _codeList = lists[index].codeInfoList.map((itm, idx) => {
              let _isScaned = itm.isScaned
              if (newcodes.indexOf(itm.code) >= 0 && !itm.isScaned) {
                num++;
                itm.isScaned = !_isScaned
                app.globalData.scanCodesList.push({
                  orderId: item.orderId,
                  goodsId: item.id,
                  nums: 1,
                  scanCodeType: that.data.index,
                  code: itm.code,
                  objectId: item.objectId
                })
              } else if (newcodes.indexOf(itm.code) >= 0 && itm.isScaned){
                wx.showToast({
                  title: '请勿重复扫描',
                  icon: 'none',
                  duration: 2000
                });

              }
              
              return {
                code: itm.code,
                isScaned: itm.isScaned
              }
            })
            _item.codeList = _codeList;
            _item.loadNums = num;
            _item.numsy = _item.nums - _item.loadNums
            total += num;
            return _item;
          }
          if (that.data.index == 3) {
            let num = item.inNums;
            let _item = item;
            let _codeList = lists[index].codeInfoList.map((itm, idx) => {
              let _isScaned = itm.isScaned
              if (newcodes.indexOf(itm.code) >= 0 && !itm.isScaned) {
                num++;
                itm.isScaned = !_isScaned
                app.globalData.scanCodesList.push({
                  orderId: item.orderId,
                  goodsId: item.id,
                  nums: 1,
                  scanCodeType: that.data.index,
                  code: itm.code,
                  objectId: item.objectId
                })
              } else if (newcodes.indexOf(itm.code) >= 0 && itm.isScaned) {
                wx.showToast({
                  title: '请勿重复扫描',
                  icon: 'none',
                  duration: 2000
                });

              }
              return {
                code: itm.code,
                isScaned: itm.isScaned
              }
              
            })
            _item.codeList = _codeList;
            _item.inNums = num;
            _item.numsy = _item.nums - _item.inNums
            total += num;
            return _item;
          }
          if (that.data.index == 4) {
            let num = item.outNums;
            let _item = item;
            let _codeList = lists[index].codeInfoList.map((itm, idx) => {
              let _isScaned = itm.isScaned
              if (newcodes.indexOf(itm.code) >= 0 && !itm.isScaned) {
                num++;
                itm.isScaned = !_isScaned
                app.globalData.scanCodesList.push({
                  orderId: item.orderId,
                  goodsId: item.id,
                  nums: 1,
                  scanCodeType: that.data.index,
                  code: itm.code,
                  objectId: item.objectId
                })
              } else if (newcodes.indexOf(itm.code) >= 0 && itm.isScaned) {
                wx.showToast({
                  title: '请勿重复扫描',
                  icon: 'none',
                  duration: 2000
                });

              }
              return {
                code: itm.code,
                isScaned: itm.isScaned
              }
            })
            _item.codeList = _codeList;
            _item.outNums = num;
            _item.numsy = _item.nums - _item.outNums
            total += num;
            return _item;
          }
        })
        console.log(total, "total")
        console.log(newNemItems,"扫描后数据----------")
        that.setData({
          nemItems: newNemItems,
          total: total
        })
        
        // for (var i = 0; i < that.data.nemItems.length; i++) {
        //   for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
        //     if (that.data.nemItems[i].codeList[j].isScaned == true) {
        //       app.globalData.scanCodesList.push({
        //         orderId: that.data.nemItems[i].orderId,
        //         goodsId: that.data.nemItems[i].id,
        //         nums:1,
        //         scanCodeType: that.data.index,
        //         code: that.data.nemItems[i].codeList[j].code
        //       })

        //     }
        //   }
        // }    
        console.log(app.globalData.scanCodesList,"555555555555555555555555")
        that.setData({
          scanCodesList: app.globalData.scanCodesList
        })
      }
    }
 
  },
  
  unique1(array) {
    var n = []; //一个新的临时数组 
    //遍历当前数组 
    for (var i = 0; i < array.length; i++) {
      //如果当前数组的第i已经保存进了临时数组，那么跳过， 
      //否则把当前项push到临时数组里面 
      if (n.indexOf(array[i]) == -1) n.push(array[i]);
    }
    return n;
  },
  over(){//完成扫描
  var that =this
    if (that.data.allnum != that.data.total){
      that.setData({
        isTip:true
      })
    }else{
      that.submit()
    }
  },
  cal(){
    var that = this
    that.setData({
      isTip: false
    })
  },
  sub(){
    var that=this
    that.submit()
  },

  tolist(){//查看扫描明细
    app.globalData.scanGoodsList=[]
  var that = this
  console.log(that.data.nemItems,"that.data.newNemItems")
  for (var i = 0; i < that.data.nemItems.length; i++) {
    for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
      if (that.data.nemItems[i].codeList[j].isScaned == true) {
        app.globalData.scanGoodsList.push({
          goodsNameWithCode: that.data.nemItems[i].goodsNameWithCode,
          orderNumber: that.data.nemItems[i].order.orderNumber,
          scanCodeType: that.data.index,
          code: that.data.nemItems[i].codeList[j].code
        })
      }
    }
  } 
  var item = JSON.stringify(app.globalData.scanGoodsList)
  console.log(app.globalData.scanGoodsList,"app.globalData.scanGoodsList")
  wx.navigateTo({
    url: '../list/list?item=' + item+"&index="+that.data.index,
  })
  },
  submit(){//提交
    
  var that=this
  console.log("完成扫描",that.data.nemItems)
  // if (that.data.index = 2) {
  //   for (var i = 0; i < that.data.nemItems.length; i++) {
  //     for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
  //       if (that.data.nemItems[i].codeList[j].isShow == true) {
  //         scanCodesList.push({
  //           orderId: that.data.nemItems[i].orderId,
  //           goodsId: that.data.nemItems[i].id,
  //           nums: that.data.nemItems[i].loadNums,
  //           scanCodeType: that.data.index,
  //           code: that.data.nemItems[i].codeList[j].code
  //         })
  //       }
  //     }
  //   }
  // }
  // if (that.data.index = 3) {
  //   for (var i = 0; i < that.data.nemItems.length; i++) {
  //     for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
  //       if (that.data.nemItems[i].codeList[j].isShow == true) {
  //         scanCodesList.push({
  //           orderId: that.data.nemItems[i].orderId,
  //           goodsId: that.data.nemItems[i].id,
  //           nums: that.data.nemItems[i].inNums,
  //           scanCodeType: that.data.index,
  //           code: that.data.nemItems[i].codeList[j].code
  //         })
  //       }
  //     }
  //   }
  // }
  // if (that.data.index = 4) {
  var scanCodesList=[]
    for (var i = 0; i < that.data.nemItems.length; i++) {
      for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
        if (that.data.nemItems[i].codeList[j].isScaned == true) {
          scanCodesList.push({
            orderId: that.data.nemItems[i].orderId,
            goodsId: that.data.nemItems[i].id,
            objectId: that.data.nemItems[i].objectId,
            nums:1,
            scanCodeType: that.data.index,
            code: that.data.nemItems[i].codeList[j].code
          })
        }
      }
    }
  // }
  // console.log(scanCodesList,"提交")
  // that.setData({
  //   scanCodesList: scanCodesList
  // })
    console.log("完成扫描", scanCodesList)
    var tokenL = app.globalData.token
    wx.request({
      url: app.globalData.apiServer + "/api/ScanCode/PostScanedNums",
      data: {
        scanedNumsList: scanCodesList,
        isSaveAndChangeState: true       
      },
      method: "POST",
      header: {
        'content-type': 'application/json',
        "Authorization": "Bearer " + tokenL,
        "LoginType": 4
      },
      success: function (res) {
        if (res.data.responseCode == 1000) {
          wx.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 2000
          }); 
          setTimeout(() => {
            wx.switchTab({
              url: '../index/index',
            })
          }, 2000)        
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          });
        }

      }

    })  
  },
  //
  subm(){//功能正在开发
    //提交
    var that = this
    // var scanCodesList = []
    // if (that.data.index == 2) {
    //   for (var i = 0; i < that.data.nemItems.length; i++) {
    //     for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
    //       if (that.data.nemItems[i].codeList[j].isShow == true) {
    //         scanCodesList.push({
    //           orderId: that.data.nemItems[i].orderId,
    //           goodsId: that.data.nemItems[i].id,
    //           nums: that.data.nemItems[i].loadNums,
    //           scanCodeType: that.data.index,
    //           code: that.data.nemItems[i].codeList[j].code
    //         })
    //       }
    //     }
    //   }
    //   
    // }
    // if (that.data.index == 3) {
    //   for (var i = 0; i < that.data.nemItems.length; i++) {
    //     for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
    //       if (that.data.nemItems[i].codeList[j].isShow == true) {
    //         scanCodesList.push({
    //           orderId: that.data.nemItems[i].orderId,
    //           goodsId: that.data.nemItems[i].id,
    //           nums: that.data.nemItems[i].inNums,
    //           scanCodeType: that.data.index,
    //           code: that.data.nemItems[i].codeList[j].code
    //         })
    //       }
    //     }
    //   }
    // }
    // if (that.data.index == 4) {
    //   for (var i = 0; i < that.data.nemItems.length; i++) {
    //     for (var j = 0; j < that.data.nemItems[i].codeList.length; j++) {
    //       if (that.data.nemItems[i].codeList[j].isShow == true) {
    //         scanCodesList.push({
    //           orderId: that.data.nemItems[i].orderId,
    //           goodsId: that.data.nemItems[i].id,
    //           nums: that.data.nemItems[i].outNums,
    //           scanCodeType: that.data.index,
    //           code: that.data.nemItems[i].codeList[j].code
    //         })
    //       }
    //     }
    //   }
    // }
    console.log(that.data.scanCodesList, "scanCodesList--------------------临时提交")
    var tokenL = app.globalData.token
    wx.request({
      url: app.globalData.apiServer + "/api/ScanCode/PostScanedNums",
      data: {
        scanedNumsList: that.data.scanCodesList,
        isSaveAndChangeState: false
      },
      method: "POST",
      header: {
        'content-type': 'application/json',
        "Authorization": "Bearer " + tokenL,
        "LoginType": 4
      },
      success: function (res) {
        if (res.data.responseCode == 1000) {
          wx.showToast({
            title: '保存成功',
            icon: 'none',
            duration: 2000
          });
          that.setData({
            isSave:true
          })
          setTimeout(() => {
            wx.switchTab({
              url: '../index/index',
            })
          }, 2000)
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          });
        }

      }

    }) 
  },
  onHide(e){
    var that = this
    var tokenL = app.globalData.token
    if (that.data.isSave == false){
      wx.request({
        url: app.globalData.apiServer + "/api/ScanCode/PostScanedNums",
        data: {
          scanedNumsList: that.data.scanCodesList,
          isSaveAndChangeState: false
        },
        method: "POST",
        header: {
          'content-type': 'application/json',
          "Authorization": "Bearer " + tokenL,
          "LoginType": 4
        },
        success: function (res) {
          if (res.data.responseCode == 1000) {
            // wx.showToast({
            //   title: '保存成功',
            //   icon: 'none',
            //   duration: 2000
            // });
            // setTimeout(() => {
            //   wx.switchTab({
            //     url: '../index/index',
            //   })
            // }, 2000)
          } else {
            // wx.showToast({
            //   title: res.data.msg,
            //   icon: 'none',
            //   duration: 2000
            // });
          }
        }
      })
    }

  },
  audioPlay() {//成功
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.stop();
    innerAudioContext.src = 'https://driverapi.dwilms.com/assets/mp3/success.mp3'//成功
    innerAudioContext.play();
    innerAudioContext.onEnded(() => {
      console.log('录音播放结束');
    })

  },
  audioPlay1() {//不存在
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.stop();
    innerAudioContext.src = 'https://driverapi.dwilms.com/assets/mp3/error.mp3'//不存在
    innerAudioContext.play();
    innerAudioContext.onEnded(() => {
      console.log('录音播放结束');
    })

  },
  audioPlay2() {//重复
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.stop();
    innerAudioContext.src = 'https://driverapi.dwilms.com/assets/mp3/repeat.mp3';//重复
    innerAudioContext.play();
    innerAudioContext.onEnded(() => {
      console.log('录音播放结束');
    })

  }
})